<template>
	<view>
		<watermark></watermark>
		<view class="remarkForm">
			<textarea class="remarkForm-textarea" :style="'width:' + textareaW + 'px;height: ' + textareaH + 'px;'" placeholder="修改群公告" type="text" v-model="form.notice" :adjust-position="false" ></textarea>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			form:{
				groupId:'',
				notice:''
			},
			back_number: 1,
			textareaW: 0,
			textareaH: 0
		};
	},
	onLoad(e) {
		var self = this;
		self.form.groupId = e.groupId;
		if(e.notice){
			self.form.notice = e.notice;
		}
		if(e.back_number){
			self.back_number = e.back_number;
		}
		uni.getSystemInfo({
			success: function (res) {
				self.textareaW = res.windowWidth - 40;
				self.textareaH = res.safeArea.height - 30;
			}
		});
	},
	methods: {
		subform(e) {
			var rules = {
				notice: {
					rules: [{
						checkType: "required",
						errorMsg: "请填写内容"
					}]
				}
			};
			var formData = JSON.parse(JSON.stringify(this.form));
			var checkRes = this.$zmmFormCheck.check(formData, rules);
			if (checkRes) {
				
				uni.showModal({
					title: '提示',
					content: '该公告会通知全部群成员，是否确认发布？',
					success: res => {
						if (res.confirm) {
                			uni.showLoading({
                				title: '提交中'
                			});
							this.$http.request({
								url: '/group/editGroupNotice',
								method: 'POST',
								data:JSON.stringify(formData),
								success: (res) => {
									if (res.data.code == 200) {
										var notice = this.form.notice;
										notice = '群公告 \n' + notice;
										uni.setStorageSync('cache_send_msg',notice);
										uni.navigateBack({
											delta: this.back_number * 1
										}).then(()=>{
											
										})
									}
								}
							});
						}
					}
				});
			} else {
				uni.showToast({
					title: this.$zmmFormCheck.error,
					icon: "none",
					position: 'bottom'
				});
			}
		}
	},
	onNavigationBarButtonTap(e) {
		switch (e.index) {
			case 0:
				this.subform()
				break;
			default:
				break;
		}
	},
};
</script>

<style scoped lang="scss">
	.remarkForm{
		margin: 10px;
	}
	.remarkForm-textarea{
		border-radius: 12rpx;
		background-color: #F7F7F7;
		line-height: 48rpx;
		padding: 5px 10px;
	}
</style>